
<?php	
	
	require_once('../../lib/'.'BaseDir.inc.htm');	
	
	require_once (EIU_CLASS.'IOClass.htm');	
	require_once (EIU_CLASS.'BlockClass.htm');	
	require_once (EIU_CLASS.'InvoiceClass.htm');	
	require_once (EIU_CLASS.'Category.htm');	
	
	set_time_limit(30);
	//Define the max number of row on a page	
	
	if(isset($_POST["CreateNew"]) and $_POST["CreateNew"]==1)
	{
		$data["dataSearch"]["TimeStart"] = date("h:i:s:u");		
		
		$invoiceObj = new io_class();
		//Lấy danh sách Invoice
		$InvcNo="";
		$SuppID="";
		$SuppName="";
		$FromDate="0000-00-00";
		$ToDate="2100-01-01";
		$Description="";
		$invoiceList = $invoiceObj->getInvoiceList($InvcNo,$SuppID,$SuppName,$FromDate,$ToDate,$Description);
		
		//Xuất ra danh sách invoice
		$i = 0;
		
		$data["dataSearch"]["ioList"] = $invoiceList;
		
		$data["dataSearch"]["Result"] = "";			
	
		//Lấy danh sách category
		$catObj = new category();
		$catList = $catObj->getCategoriesList();		
		
		$data["dataSearch"]["catList"] = $catList;
			
		
		$data["dataSearch"]["TimeFinish"] = date("h:i:s:u");
	}
	else
	{
		//Lấy danh sách category
		$catObj = new category();
		$catList = $catObj->getCategoriesList();
		
		$invoiceObj = new io_class();
		//Lấy danh sách Invoice
		$InvcNo="";
		$SuppID="";
		$SuppName="";
		$FromDate="0000-00-00";
		$ToDate="2100-01-01";
		$Description="";
		$invoiceList = $invoiceObj->getInvoiceList($InvcNo,$SuppID,$SuppName,$FromDate,$ToDate,$Description);
						
		$data["dataSearch"]["catList"] = $catList;
			
		
		
		//print_r($_POST);
		$invoiceObj = new io_class();
		
		$IOCode = $_POST["IOCode"];
		//echo $IOCode;
		//Lấy thông tin của Invoice
		$invoiceInfo = $invoiceObj->getInvcInfoByIOCode($IOCode);
		//Lấy danh sách Asset
		$assetList = $invoiceObj->getAssetListOfInvcByIOCode($IOCode);
				
		
		$data["dataSearch"]["ioList"] = $invoiceList;
		$data["dataSearch"]["invoiceInfo"] = $invoiceInfo;
		$data["dataSearch"]["assetInfo"] = $assetList;
	
		
	}	
	
	$json = json_encode($data["dataSearch"]);
	
	echo $json;	
	
?>